package com.huawei.appgallery.forum.cards.card;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewStub;
import android.view.ViewTreeObserver.OnPreDrawListener;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.huawei.appgallery.forum.base.card.ForumCard;
import com.huawei.appgallery.forum.base.card.bean.VideoInfo;
import com.huawei.appgallery.forum.cards.bean.ForumHotSpotCardBean;
import com.huawei.appgallery.forum.cards.widget.HotSpotUserTextView;
import com.huawei.appgallery.forum.posts.api.IPostDetailProtocol;
import com.huawei.appgallery.forum.posts.api.IPostDetailResult;
import com.huawei.appgallery.forum.section.api.ISectionDetailActivityProtocol;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import com.huawei.appgallery.foundation.ui.framework.widget.LineImageView;
import com.huawei.appmarket.support.video.VideoPlayer;
import o.azb;
import o.bsp;
import o.bsy.a;
import o.bsy.c;
import o.bsy.d;
import o.bsy.e;
import o.bsy.h;
import o.bsy.j;
import o.cgz;
import o.cil;
import o.cim;
import o.dof;
import o.epw;
import o.eqx;
import o.evp.b;
import o.fho;
import o.fiu;
import o.fjb;
import o.fjc;

public class ForumHotSpotCard extends ForumCard implements OnClickListener {
    private Context ʻ;
    private LinearLayout ʻॱ;
    private ImageView ʼ = null;
    private ViewStub ʽ = null;
    private HotSpotUserTextView ˊ = null;
    private VideoPlayer ˊॱ;
    private View ˋ;
    private TextView ˋॱ = null;
    protected FrameLayout ˎ;
    private TextView ˏ = null;
    private LinearLayout ˏॱ;
    private ViewStub ͺ = null;
    protected ForumHotSpotCardBean ॱ;
    private View ॱˊ;
    private LinearLayout ॱˎ;
    private TextView ॱॱ = null;
    private FrameLayout ॱᐝ;
    private LineImageView ᐝ = null;
    private LinearLayout ᐝॱ;

    public ForumHotSpotCard(Context context) {
        super(context);
        this.ʻ = context;
    }

    public cgz ˏ(View view) {
        ʽ(view);
        this.ˏ = (TextView) view.findViewById(c.ߴ);
        this.ˋ = view.findViewById(c.ߵ);
        this.ʼ = (ImageView) view.findViewById(c.ॱʼ);
        this.ˋॱ = (TextView) view.findViewById(c.ᐝᐝ);
        this.ᐝॱ = (LinearLayout) view.findViewById(c.ᐧ);
        this.ˊ = (HotSpotUserTextView) view.findViewById(c.ˌ);
        this.ॱॱ = (TextView) view.findViewById(c.ॱˈ);
        this.ॱᐝ = (FrameLayout) view.findViewById(c.ॱͺ);
        this.ˎ = (FrameLayout) view.findViewById(c.ॱʻ);
        this.ˏॱ = (LinearLayout) view.findViewById(c.ˏˏ);
        this.ॱˎ = (LinearLayout) view.findViewById(c.ˎˏ);
        this.ʻॱ = (LinearLayout) view.findViewById(c.ㆍ);
        ॱ(view);
        this.ʼ.setOnClickListener(this);
        this.ᐝॱ.setOnClickListener(this);
        this.ˏॱ.setOnClickListener(this);
        this.ʻॱ.setOnClickListener(this);
        ˊ(view);
        if (this.ʻ.getResources().getConfiguration().orientation == 2) {
            LayoutParams layoutParams = (LayoutParams) this.ˏ.getLayoutParams();
            layoutParams.weight = 0.6f;
            this.ˏ.setLayoutParams(layoutParams);
            this.ॱˎ.setOrientation(0);
            RelativeLayout.LayoutParams layoutParams2 = (RelativeLayout.LayoutParams) this.ॱˎ.getLayoutParams();
            layoutParams2.topMargin = this.ʻ.getResources().getDimensionPixelSize(e.ˊᐝ);
            layoutParams2.addRule(3, c.י);
            this.ॱˎ.setLayoutParams(layoutParams2);
        }
        if (epw.ˏ()) {
            this.ˏ.setTextColor(this.ʻ.getResources().getColor(d.ͺ));
            this.ॱॱ.setTextColor(this.ʻ.getResources().getColor(d.ˋॱ));
            this.ˋॱ.setTextColor(this.ʻ.getResources().getColor(d.ͺ));
            this.ˊ.setUserNickNameColorDark(this.ʻ.getResources().getColor(d.ˋॱ));
        }
        return this;
    }

    public void ˏ(CardBean cardBean) {
        super.ˏ(cardBean);
        if (cardBean instanceof ForumHotSpotCardBean) {
            this.ॱ = (ForumHotSpotCardBean) cardBean;
            ʻ();
            ˊ(this.ˏ, this.ॱ.ʽ());
            ॱॱ();
            eqx.ॱ(this.ʼ, this.ॱ.ᐝ().ॱ(), a.ˋ);
            ʼ();
            ˊॱ();
            ˋॱ();
            ˎ();
            ͺ();
        }
    }

    protected void ˎ() {
        ((FrameLayout.LayoutParams) this.ˎ.getLayoutParams()).setMargins(0, 0, 0, 0);
    }

    protected void ʻ() {
        if (ˏ(this.ॱ)) {
            this.ʽ.setVisibility(8);
            this.ͺ.setVisibility(0);
            return;
        }
        ॱ(this.ॱ);
        this.ʽ.setVisibility(0);
        this.ͺ.setVisibility(8);
    }

    protected void ˊ(View view) {
        this.ʽ = (ViewStub) view.findViewById(c.ˊˋ);
        this.ᐝ = (LineImageView) this.ʽ.inflate();
    }

    private void ॱ(View view) {
        this.ͺ = (ViewStub) view.findViewById(c.ॱʽ);
    }

    private boolean ˏ(ForumHotSpotCardBean forumHotSpotCardBean) {
        VideoInfo ॱˊ = forumHotSpotCardBean.ॱˊ();
        if (!forumHotSpotCardBean.ˋॱ() || !ॱ(ॱˊ)) {
            return false;
        }
        if (this.ˊॱ == null) {
            View inflate = this.ͺ.inflate();
            this.ˊॱ = (VideoPlayer) inflate.findViewById(c.ـॱ);
            this.ॱˊ = inflate.findViewById(c.ٴ);
        }
        int ॱ = (azb.ॱ(this.ʻ) - (ᐝ() * 2)) / ʽ();
        RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) this.ˊॱ.getLayoutParams();
        layoutParams.width = ॱ;
        layoutParams.height = (int) (((double) ॱ) / 1.7777777777777777d);
        this.ˊॱ.setLayoutParams(layoutParams);
        int i = c.ʻ;
        int i2 = c.ˊॱ;
        String str = (String) this.ॱˊ.getTag(i);
        String str2 = (String) this.ॱˊ.getTag(i2);
        String ˎ = ॱˊ.ˎ();
        String ˊ = ॱˊ.ˊ();
        if ((!TextUtils.isEmpty(str) && str.equals(ˎ)) || (!TextUtils.isEmpty(str2) && str2.equals(ˊ))) {
            return true;
        }
        this.ॱˊ.setTag(i, ˎ);
        this.ॱˊ.setTag(i2, ˊ);
        this.ˊॱ.setVideoBaseInfo(new b().ˎ(ॱˊ.ॱ()).ˊ(ˊ).ˋ(ˎ).ʼ(ॱˊ.ˋ()).ᐝ(ॱˊ.ˋ()).ʻ(ॱˊ.ˏ()).ॱॱ(ॱˊ.ʻ()).ॱ());
        eqx.ˎ(this.ˊॱ.ॱॱ(), ˊ);
        this.ˊॱ.ॱॱ().setContentDescription(forumHotSpotCardBean.v_());
        return true;
    }

    protected boolean ॱ(VideoInfo videoInfo) {
        if (videoInfo == null || dof.ॱ(videoInfo.ˎ())) {
            return false;
        }
        return true;
    }

    protected void ॱ(ForumHotSpotCardBean forumHotSpotCardBean) {
        String ʼ = forumHotSpotCardBean.ʼ();
        int ॱ = (azb.ॱ(this.ʻ) - (ᐝ() * 2)) / ʽ();
        this.ᐝ.setLayoutParams(new LayoutParams(ॱ, (int) (((double) ॱ) / 1.7777777777777777d)));
        this.ᐝ.setTag(forumHotSpotCardBean);
        eqx.ˏ(this.ᐝ, ʼ, "image_default_icon");
    }

    private void ॱॱ() {
        this.ˏ.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener(this) {
            final /* synthetic */ ForumHotSpotCard ॱ;

            {
                this.ॱ = r1;
            }

            public boolean onPreDraw() {
                this.ॱ.ˏ.getViewTreeObserver().removeOnPreDrawListener(this);
                LayoutParams layoutParams = (LayoutParams) this.ॱ.ˋ.getLayoutParams();
                int lineCount = this.ॱ.ˏ.getLineCount();
                int measuredHeight = this.ॱ.ˏ.getMeasuredHeight() / lineCount;
                if (lineCount == 1) {
                    layoutParams.height = measuredHeight - (this.ॱ.ʻ.getResources().getDimensionPixelSize(e.ˍ) * 2);
                } else {
                    layoutParams.height = (measuredHeight * 2) - (this.ॱ.ʻ.getResources().getDimensionPixelSize(e.ˍ) * 2);
                }
                layoutParams.topMargin = this.ॱ.ʻ.getResources().getDimensionPixelSize(e.ˍ);
                this.ॱ.ˋ.setLayoutParams(layoutParams);
                return true;
            }
        });
    }

    private void ʼ() {
        ˊ(this.ˋॱ, this.ॱ.ᐝ().ˏ());
        LayoutParams layoutParams = (LayoutParams) this.ˋॱ.getLayoutParams();
        if (bsp.ˏ(this.ˋॱ, this.ॱ.ᐝ().ˏ()) > ॱˊ()) {
            layoutParams.width = ॱˊ();
        } else {
            layoutParams.width = -2;
        }
        this.ˋॱ.setLayoutParams(layoutParams);
    }

    private void ˊॱ() {
        String string;
        String string2;
        int ˏॱ = this.ॱ.ˏॱ();
        if (ˏॱ > 999) {
            string = this.ʻ.getString(j.ᐝ, new Object[]{Integer.valueOf(999)});
        } else {
            string = this.ʻ.getResources().getQuantityString(h.ˎ, ˏॱ, new Object[]{Integer.valueOf(ˏॱ)});
        }
        int ˊॱ = this.ॱ.ˊॱ();
        if (ˊॱ > 999) {
            string2 = this.ʻ.getString(j.ʽ, new Object[]{Integer.valueOf(999)});
        } else {
            string2 = this.ʻ.getResources().getQuantityString(h.ॱ, ˊॱ, new Object[]{Integer.valueOf(ˊॱ)});
        }
        ˊ(this.ॱॱ, this.ʻ.getString(j.ˏ, new Object[]{string, string2}));
    }

    private void ͺ() {
        LayoutParams layoutParams = (LayoutParams) this.ॱᐝ.getLayoutParams();
        if (this.ॱ.ॱˍ()) {
            layoutParams.topMargin = this.ʻ.getResources().getDimensionPixelOffset(e.ʻ);
        } else {
            layoutParams.topMargin = this.ʻ.getResources().getDimensionPixelOffset(e.ˊˊ);
        }
        layoutParams.bottomMargin = this.ʻ.getResources().getDimensionPixelOffset(e.ˊˊ);
        if (this.ʻ.getResources().getConfiguration().orientation == 2) {
            int ˏॱ = ˏॱ();
            layoutParams.setMarginStart(ˏॱ);
            layoutParams.setMarginEnd(ˏॱ);
        }
        this.ॱᐝ.setLayoutParams(layoutParams);
    }

    private void ˋॱ() {
        this.ˊ.setContentWidth(ॱˊ());
        this.ˊ.setUser(this.ॱ.ͺ());
    }

    private int ॱˊ() {
        if (this.ʻ.getResources().getConfiguration().orientation == 2) {
            return (int) (((float) ((azb.ॱ(this.ʻ) - (ˏॱ() * 2)) - (this.ʻ.getResources().getDimensionPixelSize(e.ᐝॱ) * 2))) * 0.4f);
        }
        return (int) ((((float) azb.ॱ(this.ʻ)) * 0.4f) - ((float) (this.ʻ.getResources().getDimensionPixelSize(e.ᐝॱ) * 2)));
    }

    protected int ᐝ() {
        return ˏॱ() + azb.ˊ(this.ʻ);
    }

    private int ˏॱ() {
        if (this.ʻ.getResources().getConfiguration().orientation == 2) {
            return ((azb.ॱ(this.ʻ) - (this.ʻ.getResources().getDimensionPixelSize(e.ᐝॱ) * 2)) / 8) + this.ʻ.getResources().getDimensionPixelSize(e.ˏˏ);
        }
        return 0;
    }

    public int ʽ() {
        return 1;
    }

    private void ᐝॱ() {
        cil.ˋ(this.ʻ, new cim.a().ˊ(this.ॱ.ॱॱ()).ˋ());
        fjb ˎ = fho.ˏ().ˋ("Posts").ˎ("post.detail.activity");
        IPostDetailProtocol iPostDetailProtocol = (IPostDetailProtocol) ˎ.ˊ();
        iPostDetailProtocol.setDomainId(this.ॱ.ॱ());
        iPostDetailProtocol.setUri(this.ॱ.ॱॱ());
        fiu.ˊ().ॱ(this.ʻ, ˎ, new fjc<IPostDetailResult>(this) {
            final /* synthetic */ ForumHotSpotCard ˎ;

            {
                this.ˎ = r1;
            }

            public void ˎ(int i, IPostDetailResult iPostDetailResult) {
                if (i == -1) {
                    if (iPostDetailResult != null) {
                        if (iPostDetailResult.getLike() >= 0) {
                            this.ˎ.ॱ.ˊ(iPostDetailResult.getLike());
                        }
                        if (iPostDetailResult.getLikeCount() >= 0) {
                            this.ˎ.ॱ.ˏ((int) iPostDetailResult.getLikeCount());
                        }
                    }
                    this.ˎ.ˊॱ();
                }
            }
        });
    }

    private void ʻॱ() {
        cil.ˋ(this.ʻ, new cim.a().ˊ(this.ॱ.ᐝ().ॱॱ()).ˋ());
        fjb ˎ = fho.ˏ().ˋ("Section").ˎ("section_detail_activity");
        ((ISectionDetailActivityProtocol) ˎ.ˊ()).setUri(this.ॱ.ᐝ().ॱॱ());
        fiu.ˊ().ˏ(this.ʻ, ˎ);
    }

    public void onClick(View view) {
        int id = view.getId();
        if (id == c.ᐧ || id == c.ㆍ || id == c.ॱʼ) {
            ʻॱ();
        } else if (id == c.ˏˏ) {
            ᐝॱ();
        }
    }
}
